<?php
include_once("php/helper.php");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1">
    <title>	My Calendar </title>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <link href="css/dailog.css" rel="stylesheet" type="text/css" />
    <link href="css/calendar.css" rel="stylesheet" type="text/css" /> 
    <link href="css/dp.css" rel="stylesheet" type="text/css" />   
    <link href="css/alert.css" rel="stylesheet" type="text/css" /> 
    <link href="css/main.css" rel="stylesheet" type="text/css" /> 
    <link href="src/css/ui-lightness/jquery-ui-1.8.21.custom.css" rel="stylesheet" type="text/css" /> 

    <script src="src/jquery.js" type="text/javascript"></script>  
    
    <script src="src/Plugins/Common.js" type="text/javascript"></script>    
    <script src="src/Plugins/datepicker_lang_US.js" type="text/javascript"></script>     
    <script src="src/Plugins/jquery.datepicker.js" type="text/javascript"></script>

    <script src="src/Plugins/jquery.alert.js" type="text/javascript"></script>    
    <script src="src/Plugins/jquery.ifrmdailog.js" defer="defer" type="text/javascript"></script>
    <script src="src/Plugins/wdCalendar_lang_US.js" type="text/javascript"></script>    
    <script src="src/Plugins/jquery.calendar.js" type="text/javascript"></script>   
    
    
    
	<script src="src/js/jquery.ui.core.js"></script>
	<script src="src/js/jquery.ui.widget.js"></script>
	<script src="src/js/jquery.ui.mouse.js"></script>
	<script src="src/js/jquery.ui.slider.js"></script>
	
	<link rel="stylesheet" href="src/css/demos.css"/>
    
    
    
    <script type="text/javascript">
    	function getUrlParameter(param){
    		
    		var vars = [], hash;
    	    var q = document.URL.split('?')[1];
    	    if(q != undefined){
    	        q = q.split('&');
    	        for(var i = 0; i < q.length; i++){
    	            hash = q[i].split('=');
    	            if(hash[0] == param)
        	            return hash[1];
    	        }
    		}
    		return "";
        }
        
        $(document).ready(function() {     
           var view="day";   
           var userid = getUrlParameter("userid")
           if(userid != undefined && userid != "")
        	   userid = "&userid="+userid;
		   var date;
           var day = getUrlParameter("day")
           if(day != undefined && day != "")
        	   date = new Date(parseInt(day) );
           else{
        	   date = new Date();
           }
           var DATA_FEED_URL = "php/datafeed.php";//?"+userid;
           var op = {
                view: view,
                theme:3,
                showday: date,
                EditCmdhandler:Edit,
                DeleteCmdhandler:Delete,
                ViewCmdhandler:View,    
                onWeekOrMonthToDay:wtd,
                onBeforeRequestData: cal_beforerequest,
                onAfterRequestData: cal_afterrequest,
                onRequestDataError: cal_onerror, 
                autoload:true,
                readonly: <?php echo isCalendarReadOnly(); ?>,
                url: DATA_FEED_URL + "?method=list"+userid,  
                quickAddUrl: DATA_FEED_URL + "?method=add"+userid, 
                quickUpdateUrl: DATA_FEED_URL + "?method=update"+userid,
                quickDeleteUrl: DATA_FEED_URL + "?method=remove"+userid,
                scheduleUrl: DATA_FEED_URL + "?method=schedule"+userid        
          };
          var $dv = $("#calhead");
          var _MH = "400";//document.documentElement.clientHeight;
          var dvH = $dv.height() + 2;
          op.height = _MH - dvH;
          op.eventItems =[];

          var p = $("#gridcontainer").bcalendar(op).BcalGetOp();
          if (p && p.datestrshow) {
          	$("#txtdatetimeshow").text(p.datestrshow);
          }
          $("#caltoolbar").noSelect();
           
          $("#hdtxtshow").datepicker({ picker: "#txtdatetimeshow", showtarget: $("#txtdatetimeshow"),
          onReturn:function(r){                          
                          var p = $("#gridcontainer").gotoDate(r).BcalGetOp();
                          if (p && p.datestrshow) {
                              $("#txtdatetimeshow").text(p.datestrshow);
                          }
                   } 
          });
          function cal_beforerequest(type)
          {
              var t="Loading data...";
              switch(type)
              {
                  case 1:
                      t="Loading data...";
                      break;
                  case 2:                      
                  case 3:  
                  case 4:    
                      t="The request is being processed ...";                                   
                      break;
              }
              $("#errorpannel").hide();
              $("#loadingpannel").html(t).show(); 
              $("#overlay").show();   
          }
          
          function cal_afterrequest(type){
          	// Slider
        	var scrollPane = $(".slider_container");
    		var scrollContent = $("#tgTable");
        	
        	var top = 100;
          	var now = new Date();
			if(now.getDate() == this.showday.getDate() && now.getFullYear() == this.showday.getFullYear() && now.getMonth() == this.showday.getMonth()){
	        	var time = now.getHours();
	        	var minutes = (now.getMinutes()/60);
	        	 
	        	time = time+minutes;
	              
	            var top = 100-((100*time)/24);

	            var margin = scrollContent.height() - scrollPane.height();
				scrollContent.css("margin-top", (-1 * (((margin * top) / 100))) + "px");
			}
            	
        	$('#slider').slider({
        		orientation: "vertical",
        		value: top,
        		slide: function (event, ui) {

        			
        			
        			//console.log(ui.value);
        			//console.log(scrollPane.height());
        			if (scrollContent.height() > scrollPane.height()) {
						var c = 100-ui.value;
        				var margin = scrollContent.height() - scrollPane.height();
        				scrollContent.css("margin-top", (-1 * (((margin * c) / 100))) + "px");
        			} else {
        				scrollContent.css("margin-top", 0);
        			}
        		}
        	}); 
        	
			$('#slider').height($(".slider_container").height());
        	$('.scrolltimeslot').slideDown("fast");
              
            switch(type){
            	case 1:
                      $("#loadingpannel").hide();
                      $("#overlay").hide();
                      break;
                  case 2:
                  case 3:
                  case 4:
                      $("#loadingpannel").html("Success!");
                      window.setTimeout(function(){ $("#loadingpannel").hide();$("#overlay").hide();},2000);
                  break;
              }              
          
          }
          
          function cal_onerror(type,data)
          {
              $("#errorpannel").show();
          }
          function Edit(data)
          {
             var eurl="edit.php?id={0}&start={2}&end={3}&isallday={4}&title={1}";   
              if(data)
              {
                  var url = StrFormat(eurl,data);
                  OpenModelWindow(url,{ width: 600, height: 400, caption:"Manage  The Calendar",onclose:function(){
                     $("#gridcontainer").reload();
                  }});
              }
          }    
          function View(data)
          {
              var str = "";
              $.each(data, function(i, item){
                  str += "[" + i + "]: " + item + "\n";
              });
              alert(str);               
          }    
          function Delete(data,callback)
          {           
              
              $.alerts.okButton="Ok";  
              $.alerts.cancelButton="Cancel";  
              hiConfirm("Are You Sure to Delete this Event", 'Confirm',function(r){ r && callback(0);});           
          }
            function wtd(p)
            {
               if (p && p.datestrshow) {
                    $("#txtdatetimeshow").text(p.datestrshow);
                }
                $("#caltoolbar div.fcurrent").each(function() {
                    $(this).removeClass("fcurrent");
                })
                $("#showdaybtn").addClass("fcurrent");
            }
            //to show day view
            $("#showdaybtn").click(function(e) {
                //document.location.href="#day";
                $("#caltoolbar div.fcurrent").each(function() {
                    $(this).removeClass("fcurrent");
                })
                $(this).addClass("fcurrent");
                var p = $("#gridcontainer").swtichView("day").BcalGetOp();
                if (p && p.datestrshow) {
                    $("#txtdatetimeshow").text(p.datestrshow);
                }
            });
            //to show week view
            $("#showweekbtn").click(function(e) {
                //document.location.href="#week";
                $("#caltoolbar div.fcurrent").each(function() {
                    $(this).removeClass("fcurrent");
                })
                $(this).addClass("fcurrent");
                var p = $("#gridcontainer").swtichView("week").BcalGetOp();
                if (p && p.datestrshow) {
                    $("#txtdatetimeshow").text(p.datestrshow);
                }

            });
            //to show month view
            $("#showmonthbtn").click(function(e) {
                //document.location.href="#month";
                $("#caltoolbar div.fcurrent").each(function() {
                    $(this).removeClass("fcurrent");
                })
                $(this).addClass("fcurrent");
                var p = $("#gridcontainer").swtichView("month").BcalGetOp();
                if (p && p.datestrshow) {
                    $("#txtdatetimeshow").text(p.datestrshow);
                }
            });
            
            $("#showreflashbtn").click(function(e){
                $("#gridcontainer").reload();
            });
            
            //Add a new event
            $("#faddbtn").click(function(e) {
                var url ="edit.php";
                OpenModelWindow(url,{ width: 500, height: 400, caption: "Create New Calendar"});
            });
            //go to today
            $("#showtodaybtn").click(function(e) {
                var p = $("#gridcontainer").gotoDate().BcalGetOp();
                if (p && p.datestrshow) {
                    $("#txtdatetimeshow").text(p.datestrshow);
                }


            });
            //previous date range
            $("#sfprevbtn").click(function(e) {
                var p = $("#gridcontainer").previousRange().BcalGetOp();
                if (p && p.datestrshow) {
                    $("#txtdatetimeshow").text(p.datestrshow);
                }

            });
            //next date range
            $("#sfnextbtn").click(function(e) {
                var p = $("#gridcontainer").nextRange().BcalGetOp();
                if (p && p.datestrshow) {
                    $("#txtdatetimeshow").text(p.datestrshow);
                }
            });

         
            
        });

       

        
    </script>    
    
</head>
<body style="margin: auto;">
	<div class="loading"></div>


    <div>

      <div id="calhead" style="padding-left:1px;padding-right:1px;">          

      </div>
      <div style="padding:1px;">

    
        <div id="dvCalMain" class="calmain printborder">
            <div id="gridcontainer" style="overflow-y: visible;">
            </div>
        </div>
       
          
        </div>
     
  </div>
  <script>  
	   
	
		
  </script>   
   
</body>
</html>
